#pragma once
#include "LuaContext.h"
#include <map>

namespace LuaDebug {

    /**
    * @brief Convert lua_State* to 'Context' used by Context::Find and others.
    */
    class LuaContext::LuaContextManager
    {
    public:
        explicit LuaContextManager();

        ~LuaContextManager();

        /// Get weather this object is empty.
        bool IsEmpty();

        /// Add the pair of (L, ctx).
        void Add(LuaContext_ptr ctx, lua_State *L);

        /// Erase (not delete) the 'ctx' and corresponding lua_State objects.
        void Erase(LuaContext_ptr ctx);

        /// Find the Context object from a lua_State object.
        LuaContext_ptr Find(lua_State *L);

    private:
        typedef std::map<lua_State *, LuaContext_ptr > Map;
        Map m_map;
        boost::recursive_mutex m_mutex;
    };

} // namespace LuaDebug
